//
//  InvoiceController.m
//  ios-supplier
//
//  Created by Benlai on 15/8/4.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "InvoiceController.h"
#warning 发票

@interface InvoiceController () <UITextViewDelegate>

@property(nonatomic, strong) UITextView *invoice;
@property(nonatomic, strong) UITextView *aaa;

@end

@implementation InvoiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = PanelBgColorDefault;

    self.invoice = [[UITextView alloc]initWithFrame: CGRectMake(0, TopSizeFix, self.view.frame.size.width, 100)];
  
    self.aaa = [[UITextView alloc]initWithFrame:CGRectMake(0,400, 1, 1)];
    self.aaa.backgroundColor = PanelBgColorDefault;
    [self.view addSubview:self.aaa];
    
    [self.invoice setContentInset: UIEdgeInsetsMake(0, 0, 0, 0)];
//    self.invoice.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.invoice.backgroundColor = [UIColor whiteColor];
    if (self.text.length > 0 ) {
        self.invoice.text = self.text;
    }
    self.invoice.delegate = self;
    
    
    [self.view addSubview: self.invoice];
    

    self.navigationItem.title = @"发票抬头";

    
    UIButton *commitBtn = [UIButton buttonWithType: UIButtonTypeCustom];
    commitBtn.frame = CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50);
    [commitBtn setTitle: @"提交" forState: UIControlStateNormal];
    [commitBtn setBackgroundColor: UIColorFromRGB(0xf15353)];
    [commitBtn addTarget: self action: @selector(commitBtnPressed) forControlEvents: UIControlEventTouchUpInside];
    
    [self.view addSubview: commitBtn];
    
    [self.navigationItem setLeftBarButtonItem: [self createBackView]];
}

- (UIBarButtonItem *)createBackView
{
    UIButton *leftButtonItem = [UIButton buttonWithType:UIButtonTypeCustom];
        
    leftButtonItem.frame = CGRectMake(0, 0, 11, 20);
        
    [leftButtonItem setBackgroundImage:[UIImage imageNamed:@"icon-Back"] forState:UIControlStateNormal];
        
    [leftButtonItem setImageEdgeInsets: UIEdgeInsetsMake((19 - 11) / 2, 0, (19 - 11) / 2, 0)];
        
    [leftButtonItem addTarget:self action:@selector(leftButtonItemClicked) forControlEvents:UIControlEventTouchUpInside];
        
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:leftButtonItem];
        
    return item;
}
    
-(void)leftButtonItemClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.
}

- (void)textViewDidChangeSelection:(UITextView *)textView
{
//    NSRange range;
//    
//    range.location = 1000;
//    
//    range.length = 0;
//    
//    textView.selectedRange = range;
}

-(void)textViewDidEndEditing:(UITextView *)textView
{
    [textView resignFirstResponder];
}

-(void)commitBtnPressed
{
    [self.delegate invoiceInfo: self.invoice.text];
    [self.navigationController popViewControllerAnimated: YES];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.invoice resignFirstResponder];
}


@end
